@extends("layouts.common")
@section("content")
    <script src="/js/datepicker/js/bootstrap-datetimepicker.min.js"></script>
    <link rel="stylesheet" href="/js/datepicker/css/bootstrap-datetimepicker.min.css" />

    <style>
        .panel .panel-heading .panel-actions {
            float: right;
            margin-right: -15px;
            height: 40px;
            font-size: 0;
            width: 30%;
            text-align: right;
        }
    </style>
    <div class="row">
        <div class="col-lg-12">
            @if (isset($errors) && count($errors) > 0)
                <div class="alert alert-danger alert-dismissible">
                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                    <h4><i class="icon fa fa-ban"></i> 错误</h4>
                    <ul>
                        @foreach ($errors->all() as $error)
                            <li>{{ $error }}</li>
                        @endforeach
                    </ul>
                </div>
            @endif
            @if (Session::has('messages'))
                <div class="alert alert-success alert-dismissible">
                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                    <h4><i class="icon fa fa-check"></i> 成功!</h4>
                    <ul>
                        @foreach (Session::get('messages') as $error)
                            <li>{{ $error }}</li>
                        @endforeach
                    </ul>
                </div>
            @endif
        </div>
    </div>

    <div class="row">
        <div class="col-lg-12">
            <h3 class="page-header"><i class="fa fa-table"></i>日志管理</h3>
            <ol class="breadcrumb">
                <li><i class="fa fa-home"></i><a href="/welcome">Home</a></li>
                <li><i class="fa fa-table"></i>日志列表</li>
            </ol>
        </div>
    </div>
    <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h2><i class="fa fa-indent red"></i><strong>搜索</strong></h2>
                </div>
                <form action="" method="get" class="form-inline">
                    <div class="panel-body">

                        <div class="form-group">
                            <input type="text" id="datetimepicker" name="start" class="form-control" placeholder="请输入开始日期">
                        </div>
                        <div class="form-group">
                            <input type="text" id="datetimepicker1" name="end" class="form-control" placeholder="请输入截止日期">
                        </div>


                    </div>
                    <div class="panel-footer">
                        <button type="submit" class="btn btn-sm btn-success"><i class="fa fa-dot-circle-o"></i> 搜索</button>
                        <button type="reset" class="btn btn-sm btn-danger"><i class="fa fa-ban"></i> 重置</button>
                    </div>
                </form>
            </div>

        </div>
    </div>

    <div class="row">

        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h2><i class="fa fa-table red"></i><span class="break"></span><strong>日志列表</strong></h2>
                </div>
                <div class="panel-body">
                    <table class="table table-condensed">
                        <thead>
                        <tr>
                            <th>操作人</th>

                            <th>系统类型</th>

                            <th>ip地址</th>
                            <th>操作描述</th>
                            <th>操作时间</th>
                        </tr>
                        </thead>
                        <tbody>
                        @foreach($list as $val)
                            <tr>
                                <td>{{$val->username}}</td>
                                <td>{{$val->type=='1'?'总代理后台':"代理后台"}}</td>

                                <td>{{$val->ip}}</td>
                                <td>{{$val->content}}</td>
                                <td>{{$val->created_at}}</td>
                            </tr>
                        @endforeach

                        </tbody>
                    </table>
                    @include("layouts.page",['paginator'=>$list])
                </div>
            </div>
        </div><!--/col-->
    </div>
    <style>
        td,th{
            text-align: center;
        }
    </style>
    <div class="modal fade" id="active" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">警告</h4>
                </div>
                <div class="modal-body">
                    你确定要激活么？
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <a  class="btn btn-danger active btn-sm model_delete" data-val="" role="button">确定</a>
                </div>
            </div>
        </div>
    </div>


    <script>
        $(function () {

            $('#datetimepicker').datetimepicker();
            $('#datetimepicker1').datetimepicker();
            $(".btn-active").click(function(){
                $("#active").find('.modal-footer .btn-danger').attr('href', "/customer/active/" + $(this).attr("data-val"));
            });

            $(".tranid").click(function () {
                var _this=$(this);

                var text= $(this).text();
                var input= $(this).find("input").val();
                if(typeof(input) == "undefined"){
                    var val=text;
                }else{
                    var val=input;
                }
                var id= $(this).data("id");

                $(this).html("<input value='"+val+"'>");
                $(this).find("input").focus();
                $(this).find("input").on('blur',function () {
                    var input= _this.find("input").val();
                    _this.text('');
                    $.ajax({
                        url: '/customer/settran',
                        async: false,
                        type: "post",
                        data: {'id':id,'val':input,'_token':"{{csrf_token()}}"},
                        dataType: "json",
                        error:function(){

                        },
                        success: function (data) {
                            if(data=='1'){
                                _this.text(input);
                            }else if(data=='3'){
                                alert("设置失败");
                                _this.text(text);
                            }else {
                                _this.text(text);
                            }

                        }
                    });

                });

            });


            var search = location.search.substring(1);
            if (search) {
                try {
                    var query = JSON.parse('{"' + decodeURIComponent(search).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g, '":"') + '"}');

                    $.each(query, function(k, v) {
                        $('[name=' + k + ']').val(v);
                    });
                } catch (e) {
                    console.log(e);
                }

            }
        });
    </script>
@endsection